#include<iostream>
#include<memory>

class Girl;
class Boy
{
public:
    Boy()
    {
        std::cout<<"boy构造\n";
    }
    ~Boy()
    {
        std::cout<<"boy析构\n";
    }
    void SetGirl(std::shared_ptr<Girl>&g)
    {
        girlfriend=g;
    }
private:
//指向一个shared_ptr的空间，但是不会引起引用计数器加一
    std::weak_ptr<Girl>girlfriend;
};
class Girl
{
public:
    Girl()
    {
        std::cout<<"Girl构造\n";
    }
    ~Girl()
    {
        std::cout<<"Girl析构\n";
    }
    void SetGirl(std::shared_ptr<Boy>&b)
    {
        boyfriend=b;
    }
private:
    std::weak_ptr<Boy>boyfriend;
};


int main()
{
    std::shared_ptr b=std::make_shared<Boy>();
    std::shared_ptr g=std::make_shared<Girl>();
    b->SetGirl(g);
    g->SetGirl(b);
}